home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / JumpingFish.as < prev    next >
Text File  |  2006-11-29  |  5KB  |  160 lines

  1. class JumpingFish extends SSObject
  2. {
  3.    var classID = SSGlobal.CLSID_MOBILEOBJECT;
  4.    var collisionMask = SSGlobal.CLSID_SHAPE | SSGlobal.CLSID_MAINCHAR;
  5.    var assetID = "JumpingFish";
  6.    var waitOffset = 0;
  7.    var jumpStrength = 500;
  8.    var waitSyncTime = 4;
  9.    var exitedSceneAt = 0;
  10.    var immobilizeTime = 5;
  11.    var gravity = SSGlobal.GRAVITY;
  12.    var waitTime = 0;
  13.    var healthValue = -0.2;
  14.    var collision = false;
  15.    var immobilized = 0;
  16.    var editor_isItem = true;
  17.    var editor_name = "JumpingFish";
  18.    var editor_args_names = ["jumpStrength","waitSyncTime","waitOffset"];
  19.    var editor_args_values = [JumpingFish.prototype.jumpStrength,JumpingFish.prototype.waitSyncTime,JumpingFish.prototype.waitOffset];
  20.    var editor_args_types = ["number","number","number"];
  21.    var editor_args_options = [[100,1000,50],[0,15,0.1],[-5,5,0.1]];
  22.    var editor_args_descriptions = ["","",""];
  23.    var editor_args_mode = [0,0,0];
  24.    var editor_args_component = ["NumericStepper","NumericStepper","NumericStepper"];
  25.    function JumpingFish(jumpStrength, waitSyncTime, waitOffset)
  26.    {
  27.       super();
  28.       if(jumpStrength != null)
  29.       {
  30.          this.jumpStrength = jumpStrength;
  31.       }
  32.       if(waitSyncTime != null)
  33.       {
  34.          this.waitSyncTime = waitSyncTime;
  35.       }
  36.       if(waitOffset != null)
  37.       {
  38.          this.waitOffset = waitOffset;
  39.       }
  40.    }
  41.    function onAddToWorld()
  42.    {
  43.    }
  44.    function onAddToScene()
  45.    {
  46.       this.getUpdates();
  47.       if(this.launchY)
  48.       {
  49.          this.y = this.launchY;
  50.          this.syncTime();
  51.          this.target._visible = false;
  52.       }
  53.       if(this.immobilized)
  54.       {
  55.          this.immobilized = Math.max(this.immobilized - (this.world.time - this.exitedSceneAt),0);
  56.       }
  57.    }
  58.    function syncTime()
  59.    {
  60.       this.waitTime = this.waitSyncTime - (this.world.time + this.waitOffset) % this.waitSyncTime;
  61.    }
  62.    function onRemoveFromScene()
  63.    {
  64.       this.cancelUpdates();
  65.       this.exitedSceneAt = this.world.time;
  66.    }
  67.    function update(elapsed)
  68.    {
  69.       if(this.waitTime)
  70.       {
  71.          if(this.immobilized)
  72.          {
  73.             if(this.immobilized = Math.max(this.immobilized - elapsed,0))
  74.             {
  75.                return undefined;
  76.             }
  77.             this.syncTime();
  78.          }
  79.          var _loc3_ = this.waitTime;
  80.          if((this.waitTime -= elapsed) <= 0)
  81.          {
  82.             this.waitTime = 0;
  83.             this.y = this.launchY;
  84.             this.velocity.y = - this.jumpStrength;
  85.             this.target._rotation = 90;
  86.             this.splash();
  87.             this.target._visible = true;
  88.          }
  89.       }
  90.       else
  91.       {
  92.          this.velocity.y += this.gravity * elapsed;
  93.          this.moveBy(0,this.velocity.y * elapsed,0);
  94.          this.checkCollisions(elapsed);
  95.          if(this.velocity.y > 0 && this.launchY && this.y > this.launchY)
  96.          {
  97.             this.velocity.y = 0;
  98.             this.syncTime();
  99.             this.target._visible = false;
  100.             this.splash();
  101.          }
  102.          else
  103.          {
  104.             this.target._rotation += ((this.velocity.y <= 0 ? 90 : -180) - this.target._rotation) * elapsed;
  105.          }
  106.       }
  107.    }
  108.    function splash()
  109.    {
  110.       var _loc2_ = new SSParticle("splash",2,new Vector(0,0,0));
  111.       GameSound.playSound("splash");
  112.       _loc2_.x = this.x;
  113.       _loc2_.y = this.launchY + this.radius;
  114.       this.world.addObject(_loc2_);
  115.    }
  116.    function checkCollision(obj)
  117.    {
  118.       var _loc3_ = undefined;
  119.       switch(obj.classID & 4294901760)
  120.       {
  121.          case SSGlobal.CLSID_SHAPE:
  122.             if(this.launchY == null && (_loc3_ = SSCollision.sweepSphereToStaticShape(this,obj)) && _loc3_.edge.attributes.water)
  123.             {
  124.                this.collisionMask = SSGlobal.CLSID_MAINCHAR;
  125.                this.launchY = _loc3_.point.y;
  126.             }
  127.             break;
  128.          case SSGlobal.CLSID_MAINCHAR:
  129.             if(SSCollision.sweepSphereToSphere(this,obj,true))
  130.             {
  131.                return this.onCollision(obj);
  132.             }
  133.             break;
  134.       }
  135.    }
  136.    function onCollision(obj)
  137.    {
  138.       if(this.waitTime || this.immobilized)
  139.       {
  140.          return undefined;
  141.       }
  142.       if((obj.classID & 4294901760) == SSGlobal.CLSID_MAINCHAR)
  143.       {
  144.          if(obj.shield || obj.classID == SSGlobal.CLSID_VEHICLE)
  145.          {
  146.             this.immobilize();
  147.          }
  148.          else
  149.          {
  150.             obj.shiftHealth(this.healthValue,this);
  151.          }
  152.       }
  153.    }
  154.    function immobilize(obj)
  155.    {
  156.       this.velocity.y = -200;
  157.       this.immobilized = this.immobilizeTime;
  158.    }
  159. }
  160.